﻿//单击项目发起的隐藏和显示，引用新css样式的函数
function hide1(id) {
    if ($("input[type='checkbox']").is(':checked')) {
        //document.getElementById("overHead").innerText = '项目信息';
        //document.getElementById("overall-range").style.display = 'block';
        //document.getElementById("overall-NavigBar").style.display = 'block';
        //document.getElementById("overall-2").style.display = 'block';
        //document.getElementById("overall-range-txt1").style.display = 'block';
        //document.getElementById("button_step").style.display = 'block';
        //document.getElementById(id).style.display = 'none';
        //document.getElementById("schedule_1").style.backgroundColor = 'red';
        ////引用新的css样式
        //var link = document.createElement("link");
        //link.rel = "stylesheet";
        //link.type = "text/css";
        //link.href = "css/L-overall2.css";
        //document.getElementsByTagName("head")[0].appendChild(link);
        location.href = "L_Project_initiated_2.aspx";
    } else {
        alert("请阅读并同意众筹网的服务协议和众筹公告！");
    }
}

//单击下一步的隐藏和显示，引用新css样式的函数
function hide2() {
    if (document.getElementById("overall-2").style.display == "block") {

        document.getElementById("overHead").innerText = '回报设置';
        document.getElementById("overall-2").style.display = 'none';
        document.getElementById("overall-3").style.display = 'block';
        document.getElementById("button_step").style.display = 'block';
        document.getElementById("overall-range-txt1").style.display = 'none';
        document.getElementById("overall-range-txt2").style.display = 'block';
        document.getElementById("button3_Previous").style.display = 'block';
        document.getElementById("overall-range_hr").style.display = 'block';
        document.getElementById("schedule_2").style.backgroundColor = 'red';

        //引用新的css样式
        var link = document.createElement("link");
        link.rel = "stylesheet";
        link.type = "text/css";
        link.href = "css/L-overall3.css";
        document.getElementsByTagName("head")[0].appendChild(link);

        document.getElementById("overall_range_img").innerText = '温馨提示';
    }
    else if (document.getElementById("overall-3").style.display == "block") {

        document.getElementById("overHead").innerText = '发起人信息';
        document.getElementById("button_step").value = "保存草稿";
        document.getElementById("overall-3").style.display = 'none';
        document.getElementById("overall-4").style.display = 'block';
        document.getElementById("schedule_3").style.backgroundColor = 'red';
        document.getElementById("ContentPlaceHolder1_button_submit").style.display = 'block';
        document.getElementById("overall-range-txt2").style.display = 'none';
        document.getElementById("overall-range-txt3").style.display = 'block';
        //引用新的css样式
        var link = document.createElement("link");
        link.rel = "stylesheet";
        link.type = "text/css";
        link.href = "css/L-overall4.css";
        document.getElementsByTagName("head")[0].appendChild(link);
    }
    
}
//单击上一步的隐藏和显示，引用新css样式的函数
function hide3() {

    if (document.getElementById("overall-3").style.display == "block") {

        document.getElementById("overHead").innerText = '项目信息';
        document.getElementById("overall_range_img").innerText = '';
        document.getElementById("overall-range-txt1").style.display = 'block';
        document.getElementById("overall-range-txt2").style.display = 'none';
        document.getElementById("overall-range-txt3").style.display = 'none';
        document.getElementById("button_step").value = "下一步";
        document.getElementById("overall-3").style.display = 'none';
        document.getElementById("overall-2").style.display = 'block';
        document.getElementById("button_step").style.display = 'block';
        document.getElementById("button3_Previous").style.display = 'none';
        document.getElementById("schedule_2").style.backgroundColor = 'white';
        //document.getElementById(id).style.display = 'none';
        //引用新的css样式
        var link = document.createElement("link");
        link.rel = "stylesheet";
        link.type = "text/css";
        link.href = "css/L-overall2.css";
        document.getElementsByTagName("head")[0].appendChild(link);
    }
    else if (document.getElementById("overall-4").style.display == "block") {

        document.getElementById("overHead").innerText = '回报设置';
        document.getElementById("button_step").value = "下一步";
        document.getElementById("overall-4").style.display = 'none';
        document.getElementById("overall-range-txt2").style.display = 'block';
        document.getElementById("overall-3").style.display = 'block';
        document.getElementById("button_step").style.display = 'block';
        document.getElementById("button3_Previous").style.display = 'block';
        document.getElementById("schedule_3").style.backgroundColor = 'white';
        document.getElementById("ContentPlaceHolder1_button_submit").style.display = 'none';
        //document.getElementById(id).style.display = 'none';
        //引用新的css样式
        var link = document.createElement("link");
        link.rel = "stylesheet";
        link.type = "text/css";
        link.href = "css/L-overall3.css";
        document.getElementsByTagName("head")[0].appendChild(link);
    }

}

//****************针对第一种方式的具体js实现部分******************//
//****************所使用的数据是city.js******************//
var btn = document.getElementsByClassName('met1')[0];
var addrShow = document.getElementById('addr-show');
var prov = document.getElementById("prov");
var city = document.getElementById('city');
var country = document.getElementById('country');

/*用于保存当前所选的省市区*/
var current = {
    prov: '',
    city: '',
    country: ''
};

/*自动加载省份列表*/
function showProv(provpd) {
    //btn.disabled = true;
    var len = provice.length;
    for (var i = 0; i < len; i++) {
        var provOpt = document.createElement('option');
        provOpt.value = provOpt.innerText = provice[i]['name'];
        document.getElementById(''+provpd).appendChild(provOpt);
    }
};

/*根据所选的省份来显示城市列表*/
function showCity(obj, provpd1) {
    var val = obj.options[obj.selectedIndex].value;
    if (obj != '') {
        $('#' + provpd1).find("option").remove();
    }
    if (val != '') {
        //查找省的索引
        var len = provice.length;
        let provIndex = 0;
        for (var i = 0; i < len; i++) {
            if (val == provice[i]['name']) {
                provIndex = i;
                break;
            }
        }

        var cityLen = provice[provIndex]["city"].length;
        for (var j = 0; j < cityLen; j++) {
            var cityOpt = document.createElement('option');
            cityOpt.value = cityOpt.innerText = provice[provIndex]["city"][j].name;
            document.getElementById('' + provpd1).appendChild(cityOpt);
        }
    }
}

/*根据所选的城市来显示县区列表*/
function showCountry(obj) {
    var val = obj.options[obj.selectedIndex].value;
    if (val != current.city) {
        current.city = val;
        addrShow.value = '';
        btn.disabled = true;
        country.length = 1; //清空之前的内容只留第一个默认选项
    }

    //查找省的索引
    var provLen = provice.length;
    let provIndex = 0;
    for (var i = 0; i < provLen; i++) {
        if (current.prov == provice[i]['name']) {
            provIndex = i;
            break;
        }
    }

    //查找城市的索引
    var cityLen = provice[provIndex]["city"].length;
    let cityIndex = 0;
    for (var i = 0; i < cityLen; i++) {
        if (current.city == provice[provIndex]["city"][i].name) {
            cityIndex = i;
            break;
        }
    }

    if (val != '') {
        var countryLen = provice[provIndex]["city"][cityIndex].districtAndCounty.length;
        if (countryLen == 0) {
            addrShow.value = current.prov + '-' + current.city;
            return;
        }
        for (var n = 0; n < countryLen; n++) {
            var countryOpt = document.createElement('option');
            countryOpt.innerText = provice[provIndex]["city"][cityIndex].districtAndCounty[n];
            countryOpt.value = provice[provIndex]["city"][cityIndex].districtAndCounty[n];
            country.appendChild(countryOpt);
        }
    }
}

/*选择县区之后的处理函数*/
function selecCountry(obj) {
    current.country = obj.options[obj.selectedIndex].value;
    if ((current.city != '') && (current.country != '')) {
        btn.disabled = false;
    }
}



